//
// Unihan Input Method
//
// Copyright © 2002-2007 Sun Wah Linux Ltd.
//
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
// USA
//
// $Id: key.c 757 2007-05-10 08:19:31Z roger $
//

#include <string.h>
#include "key.h"
#include "table.h"

int
append_key(UnihanIM *uim, IMKeyEvent *kev)
{
	TableDataPerSession *ds = (TableDataPerSession *)uim->sessionUserData;
	int len = strlen(ds->keybuf);

	if (len < PREEDIT_LEN_MAX) {
		ds->keybuf[len] = kev->keyChar;
		ds->keybuf[len+1] = 0;
		return len+1;
	}
	else {
		uim->m->beep(uim);
		return 0;
	}
}

int
throw_a_key(UnihanIM *uim)
{
	TableDataPerSession *ds = (TableDataPerSession *)uim->sessionUserData;
	int len = strlen(ds->keybuf);

	ds->keybuf[len] = 0;
	return len-1;
}

// vi:ts=4:nowrap:cin:expandtab
